package com.store.service.impl;

import com.store.entity.Product;
import com.store.mapper.ProductMapper;
import com.store.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.store.service.ex.NotFindProductException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cai
 * @since 2022-07-13
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Autowired
    ProductMapper productMapper;

    @Override
    public List<Product> showHotProduct() {
        List<Product> list= productMapper.selectByHot();
        for (Product product : list) {
            product.setPriority(null);
            product.setCreatedUser(null);
            product.setCreatedTime(null);
            product.setModifiedUser(null);
            product.setModifiedTime(null);
        }
        return list;
    }

    @Override
    public Product myGetById(Integer id) {
        Product product= productMapper.selectById(id);
        if(product==null){
            throw new NotFindProductException("未发现商品信息");
        }
        product.setPriority(null);
        product.setCreatedUser(null);
        product.setCreatedTime(null);
        product.setModifiedUser(null);
        product.setModifiedTime(null);
        return product;
    }
}
